#ifndef __EV_SATELLITE_SI_DATA_H__
#define __EV_SATELLITE_SI_DATA_H__


#include<stdint.h>
#include<string>
#include"TimePoint.hpp"
#include"rapidjson/document.h"

namespace SC_SUN
{

struct EvSatelliteSIData
{

    //////基本信息//////
    /*
    长度：5位
    范围：1- SAT_NUM
    格式：SAT+XXXXX
    【SAT0000*】
    【SAT000**】
    【SAT00***】
    【SAT0****】
    【SAT*****】
    */
    std::string SAT_SN;

    //////初始历元//////
    TimePoint mStartTime;

    //////卫星信息//////
    double SAT_ATN[3];                                  ///< 天线安装位置,单位：米，坐标系：本体系
    double CST_MASS;                                    ///< 质量，单位：千克
    double CST_AAD;                                     ///< 迎风面积，单位：米^2
    double CST_ASR;                                     ///< 受晒面积，米^2
    double SAT_ATN_DR;                                  ///< 天线相位中心偏差半径，单位：米
    double SAT_ATN_DA;                                  ///< 天线相位中心偏差角，单位：度
    double SAT_SQ;                                      ///< 频率，单位：赫兹
    double SAT_SQ_ER;                                   ///< 频率误差，单位：赫兹
    double SAT_SQ_DR;                                   ///< 频率漂移率，单位：赫兹/天
    double SAT_HD;                                      ///< 硬件延迟，单位：纳秒

auto ObjToJsonObject(rapidjson::Document& doc)
{
    using namespace rapidjson;

    Value obj(kObjectType);
    obj.AddMember(Value("SAT_SN", doc.GetAllocator()), Value(SAT_SN.data(), doc.GetAllocator()), doc.GetAllocator());
    obj.AddMember(Value("JD_MS", doc.GetAllocator()), Value(mStartTime.JD), doc.GetAllocator());

    Value value4(kArrayType);
    value4.PushBack(mStartTime.YY, doc.GetAllocator());
    value4.PushBack(mStartTime.MM, doc.GetAllocator());
    value4.PushBack(mStartTime.DD, doc.GetAllocator());
    value4.PushBack(mStartTime.HH, doc.GetAllocator());
    value4.PushBack(mStartTime.MI, doc.GetAllocator());
    value4.PushBack(mStartTime.SS, doc.GetAllocator());
    obj.AddMember(Value("UTC_start", doc.GetAllocator()), value4, doc.GetAllocator());

    Value value3(kArrayType);
    value3.PushBack(SAT_ATN[0], doc.GetAllocator());
    value3.PushBack(SAT_ATN[1], doc.GetAllocator());
    value3.PushBack(SAT_ATN[2], doc.GetAllocator());
    obj.AddMember(Value("SAT_ATN", doc.GetAllocator()), value3, doc.GetAllocator());

    obj.AddMember(Value("CST_MASS", doc.GetAllocator()), Value(CST_MASS), doc.GetAllocator());
    obj.AddMember(Value("CST_AAD", doc.GetAllocator()), Value(CST_AAD), doc.GetAllocator());
    obj.AddMember(Value("CST_ASR", doc.GetAllocator()), Value(CST_ASR), doc.GetAllocator());
    obj.AddMember(Value("SAT_ATN_DR", doc.GetAllocator()), Value(SAT_ATN_DR), doc.GetAllocator());
    obj.AddMember(Value("SAT_ATN_DA", doc.GetAllocator()), Value(SAT_ATN_DA), doc.GetAllocator());
    obj.AddMember(Value("SAT_SQ", doc.GetAllocator()), Value(SAT_SQ), doc.GetAllocator());
    obj.AddMember(Value("SAT_SQ_ER", doc.GetAllocator()), Value(SAT_SQ_ER), doc.GetAllocator());
    obj.AddMember(Value("SAT_SQ_DR", doc.GetAllocator()), Value(SAT_SQ_DR), doc.GetAllocator());
    obj.AddMember(Value("SAT_HD", doc.GetAllocator()), Value(SAT_HD), doc.GetAllocator());

    return obj;
}


static EvSatelliteSIData JsonObjectToObject(rapidjson::GenericObject<true, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteSIData ret;
    
    ret.SAT_SN = obj["SAT_SN"].GetString();
    ret.mStartTime.JD = obj["JD_MS"].GetDouble();

    auto array = obj["UTC_start"].GetArray();
    ret.mStartTime.YY = array[0].GetUint();
    ret.mStartTime.MM = array[1].GetUint();
    ret.mStartTime.DD = array[2].GetUint();
    ret.mStartTime.HH = array[3].GetUint();
    ret.mStartTime.MI = array[4].GetUint();
    ret.mStartTime.SS = array[4].GetDouble();

    auto array1 = obj["SAT_ATN"].GetArray();
    ret.SAT_ATN[0] = array1[0].GetDouble();
    ret.SAT_ATN[1] = array1[1].GetDouble();
    ret.SAT_ATN[2] = array1[2].GetDouble();

    ret.CST_MASS = obj["CST_MASS"].GetDouble();
    ret.CST_AAD = obj["CST_AAD"].GetDouble();
    ret.CST_ASR = obj["CST_ASR"].GetDouble();
    ret.SAT_ATN_DR = obj["SAT_ATN_DR"].GetDouble();
    ret.SAT_ATN_DA = obj["SAT_ATN_DA"].GetDouble();
    ret.SAT_SQ = obj["SAT_SQ"].GetDouble();
    ret.SAT_SQ_ER = obj["SAT_SQ_ER"].GetDouble();
    ret.SAT_SQ_DR = obj["SAT_SQ_DR"].GetDouble();
    ret.SAT_HD = obj["SAT_HD"].GetDouble();

    return ret;
}


static EvSatelliteSIData JsonObjectToObject2(rapidjson::GenericObject<false, rapidjson::Value> obj)
{
    using namespace rapidjson;

    EvSatelliteSIData ret;

    ret.SAT_SN = obj["SAT_SN"].GetString();
    ret.mStartTime.JD = obj["JD_MS"].GetDouble();

    auto array = obj["UTC_start"].GetArray();
    ret.mStartTime.YY = array[0].GetUint();
    ret.mStartTime.MM = array[1].GetUint();
    ret.mStartTime.DD = array[2].GetUint();
    ret.mStartTime.HH = array[3].GetUint();
    ret.mStartTime.MI = array[4].GetUint();
    ret.mStartTime.SS = array[4].GetDouble();

    auto array1 = obj["SAT_ATN"].GetArray();
    ret.SAT_ATN[0] = array1[0].GetDouble();
    ret.SAT_ATN[1] = array1[1].GetDouble();
    ret.SAT_ATN[2] = array1[2].GetDouble();

    ret.CST_MASS = obj["CST_MASS"].GetDouble();
    ret.CST_AAD = obj["CST_AAD"].GetDouble();
    ret.CST_ASR = obj["CST_ASR"].GetDouble();
    ret.SAT_ATN_DR = obj["SAT_ATN_DR"].GetDouble();
    ret.SAT_ATN_DA = obj["SAT_ATN_DA"].GetDouble();
    ret.SAT_SQ = obj["SAT_SQ"].GetDouble();
    ret.SAT_SQ_ER = obj["SAT_SQ_ER"].GetDouble();
    ret.SAT_SQ_DR = obj["SAT_SQ_DR"].GetDouble();
    ret.SAT_HD = obj["SAT_HD"].GetDouble();

    return ret;
}


};

}



#endif 